home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / src / td01_src.lha / td_r0.1 / developing / PolygonTest / polygon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-07  |  3.9 KB  |  150 lines

  1. /*
  2. ** ANSI standart includes
  3. */
  4. #include <stdio.h>
  5.  
  6. /*
  7. ** Amiga includes
  8. */
  9.  
  10. /*
  11. ** Amiga libraries includes
  12. */
  13.  
  14. /*
  15. ** Project includes
  16. */
  17. #include "td.h"
  18. #include "geoa.h"
  19.  
  20. /************************** test main *******************************/
  21. void main(void) {
  22.   ULONG space,i,ret,offset;
  23.   TDfloat fa3[3];
  24.   STRPTR name,ext;
  25.   UBYTE  outfile[200];
  26.     
  27.   if((space = tdSpaceNew())!=0) {
  28.     printf("Space created\n");
  29.  
  30.     tdAdd(space,TD_SURFACE);
  31.     i=tdNofGet(space,TD_MATERIAL);
  32.     fa3[0]=1.0,fa3[1]=0.0,fa3[2]=0.0;
  33.     tdMaterialSetfa(space,TD_DIFFUSE,i,fa3);
  34.     tdNameSet(space,TD_MATERIAL,i,"red");
  35.     tdMaterialSetf(space,TD_SHININESS,i,0.8);
  36.     tdMaterialSetf(space,TD_TRANSPARENCY,i,0.2);
  37.  
  38.     name[0]='\0';
  39.     tdNameGet(space,TD_MATERIAL,i,&name);
  40.     printf("Created surface %s\n",name);
  41.  
  42.     tdAdd(space,TD_SURFACE);
  43.     i=tdNofGet(space,TD_MATERIAL);
  44.     fa3[0]=0.0,fa3[1]=0.0,fa3[2]=1.0;
  45.     tdMaterialSetfa(space,TD_DIFFUSE,i,fa3);
  46.     tdNameSet(space,TD_MATERIAL,i,"blue");
  47.     tdMaterialSetf(space,TD_SHININESS,i,0.8);
  48.     tdMaterialSetf(space,TD_TRANSPARENCY,i,0.2);
  49.  
  50.     name[0]='\0';
  51.     tdNameGet(space,TD_MATERIAL,i,&name);
  52.     printf("Created surface %s\n",name);
  53.  
  54.     tdAdd(space,TD_POLYMESH);
  55.     tdNameSet(space,TD_OBJECT,1,"RedBlue");
  56.  
  57.     name[0]='\0';
  58.     tdNameGet(space,TD_OBJECT,1,&name);
  59.     printf("Created polymesh %s\n",name);
  60.  
  61.     tdCurrent(space,TD_OBJECT,1);
  62.       tdCurrent(space,TD_MATERIAL,1);
  63.         tdBegin(space,TD_MATGROUP);
  64.           tdBegin(space,TD_POLYGON);
  65.            tdVertexAdd3f(space,-10.0,-10.0,0.0);
  66.             tdVertexAdd3f(space,10.0,10.0,0.0);
  67.             tdVertexAdd3f(space,-10.0,10.0,0.0);
  68.       tdCurrent(space,TD_MATERIAL,2);
  69.         tdBegin(space,TD_MATGROUP);
  70.           tdBegin(space,TD_POLYGON);
  71.             tdVertexAdd3f(space,-10.0,-10.0,0.0);
  72.             tdVertexAdd3f(space,10.0,-10.0,0.0);
  73.             tdVertexAdd3f(space,10.0,10.0,0.0);
  74.         tdEnd(space,TD_MATGROUP);
  75.  
  76.       printf("The polymesh has :\n");
  77.       printf(" a total number of vertices        : %ld\n",tdNofGet(space,TD_VERTEX));
  78.       printf(" a total number of polygons        : %ld\n",tdNofGet(space,TD_POLYGON));
  79.       printf(" a total number of material groups : %ld\n",tdNofGet(space,TD_MATGROUP));
  80.     tdEnd(space,TD_OBJECT);
  81.  
  82.     printf("The space has :\n");
  83.     printf(" a total number of materials       : %ld\n",tdNofGet(space,TD_MATERIAL));
  84.  
  85. /*    
  86. {
  87. STRPTR *formats=NULL;
  88.  
  89. printf("Filling arrays : %ld\n",fill3DFormatArrays());
  90.  
  91. printf("Number of supported 3D savers : %ld\n",tdo3DSaverNofGet());
  92. formats=tdo3DSaverNamesGet();
  93. if(formats!=NULL) {
  94.     i=0;
  95.     printf("Supported savers are :\n\n");
  96.     while(formats[i]!=NULL) {
  97.         printf("   %s -> %s\n",formats[i],tdo3DSaverExtGet(formats[i]));
  98.         i++;
  99.     }
  100.     printf("\n");
  101. }
  102.  
  103. printf("Saving mesh : %ld\n\n",meshSave3D(mesh,formats[i-1],"ram:test",NULL));
  104.  
  105. printf("Number of supported 3D loaders : %ld\n",tdo3DLoaderNofGet());
  106. formats=tdo3DLoaderNamesGet();
  107. if(formats!=NULL) {
  108.     i=0;
  109.     printf("Supported loaders are :\n\n");
  110.     while(formats[i]!=NULL) {
  111.         printf("   %s\n",formats[i]);
  112.         i++;
  113.     }
  114.     printf("\n");
  115. }
  116.  
  117. printf("Loading mesh : %ld\n\n",meshLoad3D(&mesh2,"ram:test",NULL));
  118.  
  119. free3DFormatArrays();
  120. printf("Arrays free\n");
  121. }
  122. */
  123.  
  124.  
  125. #define INFILE "ram:tank.geo"
  126. #define OUTFILE "ram:pout"
  127.  
  128.  
  129.     printf("Trying to load a file\n");
  130.     if((ret=td3XCheckFile(INFILE))==ER_NOERROR) {
  131.         printf("Seems to be a %s file\n",td3XName());
  132.         if((ret=td3XLoad(space,INFILE,TD_OBJECT,NULL,&offset))==ER_NOERROR) {
  133.             printf("Total number of objects : %ld\n",tdNofGet(space,TD_OBJECT));
  134.         } else {
  135.             printf("Object not loaded : %ld offset (%ld)\n",ret,offset);
  136.         }
  137.     } else {
  138.         printf("File type not known : %ld\n",ret);
  139.     }
  140.  
  141.     if((ext=td3XExt())!=NULL) {
  142.         sprintf(outfile,"%s.%s",OUTFILE,ext);
  143.     }
  144.     if((ret=td3XSave(space,outfile,TD_OBJECT,2,NULL))!=ER_NOERROR) printf("Save failed : %ld\n",ret);
  145.     else printf("Saved\n");
  146.  
  147.     printf("Deleting space\n");
  148.     tdSpaceDelete(space);
  149.   }
  150. }